#include "glBlend.h"

#define glColorMaskIndexed glColorMaskIndexedEXT

void glSetBlendState(const GL_BLEND_DESC *pDesc, const float BlendFactor[4])
{
    if (pDesc == NULL)
        return;

    if (pDesc->BlendEnable[0])
    {
        glEnable(GL_BLEND);

        glBlendFuncSeparate(pDesc->SrcBlend,
                            pDesc->SrcBlendAlpha,
                            pDesc->DstBlend,
                            pDesc->DstBlendAlpha);

        glBlendEquation( pDesc->BlendOp );
        
        glBlendColor( BlendFactor[0], 
                      BlendFactor[1], 
                      BlendFactor[2], 
                      BlendFactor[3] );
    }
    else
        glDisable(GL_BLEND);

    for (int idx = 0; idx < 8; idx++)
        glColorMaskIndexed(idx, pDesc->RenderTargetWriteMask[idx] & GL_COLOR_WRITE_ENABLE_RED, 
                                pDesc->RenderTargetWriteMask[idx] & GL_COLOR_WRITE_ENABLE_GREEN,
                                pDesc->RenderTargetWriteMask[idx] & GL_COLOR_WRITE_ENABLE_BLUE,
                                pDesc->RenderTargetWriteMask[idx] & GL_COLOR_WRITE_ENABLE_ALPHA);

}